<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
  <head>
    <title>想法</title>
    <link rel="stylesheet" href="css/bootstrap.min.css" />
	<script type="text/javascript" src="js/jquery.js"></script>
	<script type="text/javascript" src="js/bootstrap.min.js"></script>
	<script type="text/javascript" src="js/timeago.js"></script>
  </head>
  
  <body>
    <%@include file="include/topbar.jsp" %>

	<div class="container" style="margin-top: 60px">
			<div class="row">
				<jsp:include page="include/left.jsp">
					<jsp:param value="idea" name="tag"/>
				</jsp:include>
	<div class="span9">
			<ul style="margin-bottom:0px;border-radius: 3px 3px 0 0;margin-top:15px" class="breadcrumb">
				<li class="active">
					<a href="idea.jspx"><i class="icon-fire"></i>想法</a>&gt;${idea.title}
				</li>
				
			</ul>
			<div class="wall">
				  <div class="page-header">
					<h3>${idea.title}&nbsp;&nbsp;<small>${idea.employeeId eq employee.id ? '我' : idea.name}发布于 <abbr class="timeago" title="${idea.createtime}">${idea.createtime}</abbr></small></h3>
				  </div>
				  <pre>${idea.content}</pre>
				  
				  <div class="line">
					评论
				  </div>
					<textarea rows="5" class="span8"></textarea>
					<br>
					<button class="btn" id="sendcomment">发布</button>
				 <div id="log">
				 <c:forEach var="comment" items="${list}">
				 <blockquote>
				 ${comment.content}
				  <small>
					${comment.employeeId eq employee.id ? '我' : comment.name}发布于<abbr class="timeago" title="${comment.createtime}" rel="${comment.id}">${comment.createtime}</abbr>
					<c:if test="${comment.employeeId eq employee.id}">
					<a title="编辑" href=""><i class="icon-pencil"></i></a>
				    <a title="删除" href=""><i class="icon-trash"></i></a>
				    </c:if>
				  </small>
				</blockquote>
				</c:forEach>
				</div>
				<a href="idea.jspx">←返回想法列表</a>
			</div>
		</div>
		</div>
	</div>
	
	<script type="text/javascript">
		$(function() {
			$("abbr.timeago").timeago();
		});
		
		$(function() {
			var ideaId = "${idea.id}";
			var ideaTitle = "${idea.title}";
			$("#sendcomment").click(function() {
				var comment = $("textarea").val();
				if(comment.trim() != "" && ideaId.trim() != "") {
					var abbr = $("#log blockquote:first-child small abbr");
					var lastTime = abbr.attr("title");
					var commentId = abbr.attr("rel");
					if(!lastTime) {
						lastTime = "0";
						commentId = "0";
					}
					
					$.ajax({
						url : 'ideacomment.jspx',
						type : 'POST',
						dataType: 'json',
						data : {
							ideaid : ideaId,
							time : lastTime,
							comment : comment,
							commentid : commentId,
							title : ideaTitle
						},
						success : function(data) {
							$("textarea").val("");
							$.each(data, function(i, n) {
								var small = $("<small>").text(n.name + "发表于");
			  					var abbr = $("<abbr>").attr({"class" : "timeago", "title" : n.createtime, "rel" : n.id});
			  					small.append(abbr);
			  					$("<blockquote>").text(n.content).append(small).prependTo($("#log"));
							});
							
							$("abbr.timeago").timeago();
						}
					});
				}
			});
		});
	</script>
</body>
</html>
